Javascript function

  • function is an Object in javascript
  • Javascript function has properties as well as methods.
  • Normal function Declaration
    1. function functionName(argumentparemeters){     }
  • Anonymous Function
    1. var pp (variable which will save the return value from function)=function(){
    2. alert("Hi this is anonymous function");
    3. }
  • Constructor
    1. function Memeber(a,b){
    2. this.name=a;
    3. this.skill=b;
    4. }
    5. var t=new Member("Pavan","Servicenow");
    6. var g=new Member("Pankaj",Java");
  • function myFunction(a, b) {
    return a * b;
    }var x = myFunction(4, 3);
  •      Arrow Functions
    1. // ES5
      var x = function(p, q) {
      return p * q;
      }// ES6
      const x = (p, q) => p * q;
  • Call Back function
    1. A JavaScript Callback Function is a function that is passed as a parameter to another JavaScript function, and the callback function is run inside of the function it was passed into.
      1. function p1(x){ return x;     };
      2. function p2(p1(1))
      1. function p1(x){ return  x;}
      2. function p2(b, callback){    callback(b);}
      3. p2(2,p1);
      4. p2(3,function(){alert("Hi");})